package com.vincent.kdp.Activity;

import android.os.Bundle;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.util.TypedValue;
import android.view.View;
import android.widget.ExpandableListView;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.vincent.kdp.R;
import com.vincent.kdp.adapter.CartExpandableListAdapter;
import com.vincent.kdp.bean.Paginator;
import com.vincent.kdp.http.RequestCallBack;
import com.vincent.kdp.ui.bean.response.UncheckGoodsListOutput;
import com.vincent.kdp.ui.other.repository.UncheckGoodsListRepository;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

import static android.R.attr.data;

public class UncheckGoodListActivity extends AppCompatActivity {

    @Bind(R.id.bottom_line_tv)
    TextView bottomLineTv;
    @Bind(R.id.back_img)
    ImageView backImg;
    @Bind(R.id.toolbar_center_tv)
    TextView toolbarCenterTv;
    @Bind(R.id.layout_toolbar_two)
    RelativeLayout layoutToolbarTwo;
    @Bind(R.id.un_check_list)
    ExpandableListView unCheckList;
    @Bind(R.id.SwipeRefreshLayout)
    SwipeRefreshLayout swipeRefreshLayout;

    private UncheckGoodListActivity thisActivity;
    private UncheckGoodsListRepository uncheckGoodsListRepository=new UncheckGoodsListRepository();

    private List<UncheckGoodsListOutput.Data> data = new ArrayList<>();
    public  boolean hasNext=true;

    private CartExpandableListAdapter adapter;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_uncheck_good_list);
        ButterKnife.bind(this);
        toolbarCenterTv.setText("未盘点列表");
        adapter=new CartExpandableListAdapter(this);
        unCheckList.setAdapter(adapter);
        initRecycleView();
        reqData();

        for (int i = 0; i < data.size(); i++) {
            System.out.println("9999999999999999999999999"+data.size());
            unCheckList.expandGroup(i);
        }

    }

    private void initRecycleView() {
        thisActivity=this;

        swipeRefreshLayout.setProgressViewOffset(false, 70, (int) TypedValue
                .applyDimension(TypedValue.COMPLEX_UNIT_DIP, 90, getResources()
                        .getDisplayMetrics()));
        swipeRefreshLayout.setColorSchemeResources(R.color.black);

        //刷新
        swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                data.clear();
                reqData();
            }
        });

    }
    public void reqData() {
        uncheckGoodsListRepository.reqUncheckGoodList(new RequestCallBack() {
            @Override
            public void onSuccess(Object object) {
                UncheckGoodsListOutput uncheckGoodsListOutput = (UncheckGoodsListOutput) object;

                if(uncheckGoodsListOutput.getData().size()==0){
                    //无数据

                }else{
                        data.addAll(uncheckGoodsListOutput.getData());
//                    swipeRefreshLayout.setRefreshing(false);
                    adapter.setList(data);
                    adapter.notifyDataSetChanged();
//                    for (int i = 0; i < data.size(); i++) {
//                        System.out.println("9999999999999999999999999"+data.size());
//                        unCheckList.expandGroup(i);
//                    }



                }
                swipeRefreshLayout.setRefreshing(false);
            }

            @Override
            public void onFalse(String msg) {
            }
        });
    }

    @OnClick(R.id.back_img)
    public void onViewClicked() {
        finish();
    }
}
